//
//  PGPostViewCell.m
//  youqu
//
//  Created by 彭鹏 on 16/10/16.
//  Copyright © 2016年 pengpeng. All rights reserved.
//

#import "PGPostViewCell.h"

#import "PGPostViewModel.h"
#import "PGPostItem.h"

#import "PGTopView.h"
#import "PGPictureView.h"
#import "PGVideoView.h"
#import "PGVoiceView.h"
#import "PGHotCommentView.h"
#import "PGBottomView.h"
@interface PGPostViewCell ()
/**topView*/
@property (nonatomic, weak) PGTopView *topView;

/**pictureView*/
@property (nonatomic, weak) PGPictureView *pictureView;
/**videoView*/
@property (nonatomic, weak) PGVideoView *videoView;

/**voiceView*/
@property (nonatomic, weak) PGVoiceView *voiceView;

/**hotCommentView*/
@property (nonatomic, weak) PGHotCommentView *hotCommentView;

/**PGBottomView*/
@property (nonatomic, weak) PGBottomView *bottomView;

@end

@implementation PGPostViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setFrame:(CGRect)frame {
    frame.origin.y += 10;
    frame.size.height -= 10;
    [super setFrame:frame];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage stretchableImageWithName:@"mainCellBackground"]];
        
        self.backgroundColor = [UIColor lightGrayColor];
        
        //顶部的view
        PGTopView *topView = [PGTopView topView];
        [self.contentView addSubview:topView];
        _topView = topView;
        
        //图片
        PGPictureView *pictureView = [PGPictureView pictureView];
        [self.contentView addSubview:pictureView];
        _pictureView = pictureView;
        
        //视频
        PGVideoView *videoView = [PGVideoView videoView];
        [self.contentView addSubview:videoView];
        _videoView = videoView;
        
        //视频
        PGVoiceView *voiceView = [PGVoiceView voiceView];
        [self.contentView addSubview:voiceView];
        _voiceView = voiceView;
        
        //最热评论
        PGHotCommentView *hotCommentView = [PGHotCommentView hotCommentView];
        [self.contentView addSubview:hotCommentView];
        _hotCommentView = hotCommentView;
        
        //底部工具条
        PGBottomView *bottomView = [PGBottomView bottomView];
        [self.contentView addSubview:bottomView];
        _bottomView = bottomView;
        
        
    }
    
    
    return self;
    
}


- (void)setViewModel:(PGPostViewModel *)viewModel {
    _viewModel = viewModel;
    _topView.item = viewModel.item;
    _topView.frame = viewModel.topViewFrame;
    
    
    
    
    
    
    switch (viewModel.item.type) {
        case PGPostTypeAll:
        {
            
        }
            break;
        case PGPostTypeVideo:
        {
            _pictureView.hidden = YES;
            _videoView.hidden = NO;
            _videoView.item = viewModel.item;
            _videoView.frame = viewModel.middleViewFrame;
        }
            break;
        case PGPostTypeVoice:
        {
            _videoView.hidden = YES;
            _pictureView.hidden = YES;
            _voiceView.hidden = NO;
            _voiceView.item = viewModel.item;
            _voiceView.frame = viewModel.middleViewFrame;
        }
            break;
        case PGPostTypePicture:
        {
            _voiceView.hidden = YES;
            _videoView.hidden = YES;
            _pictureView.hidden = NO;
            _pictureView.item = viewModel.item;
            _pictureView.frame = viewModel.middleViewFrame;
        }
            break;
        case PGPostTypeText:
        {
            _voiceView.hidden = YES;
            _videoView.hidden = YES;
            _pictureView.hidden = YES;
        }
            break;
    }
    
    
    if (viewModel.item.topCommentItem) {
        _hotCommentView.hidden = NO;
        _hotCommentView.frame = viewModel.hotCommentViewFrame;
        _hotCommentView.item = viewModel.item;
    }else {
        _hotCommentView.hidden = YES;
    }
    
    _bottomView.frame = viewModel.bottomViewFrame;
    _bottomView.item = viewModel.item;
   
    
    
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
